package com.company.disjSets;

import javax.swing.*;
import java.awt.*;

/**
 * Created by v on 16-12-13.
 */
public class LabyrinthUI extends JApplet {
    LabyrinthPanel panel;

    public LabyrinthUI(){
        panel=new LabyrinthPanel(40,30);
        add(panel);
    }

    @Override
    public void init() {
        super.init();
        setSize(600,400);
    }

    private class LabyrinthPanel extends JPanel{
        private Labyrinth labyrinth;

        public LabyrinthPanel(int lines,int rows){
            labyrinth=new Labyrinth(lines,rows);
            repaint();
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            for(int i=0;i<labyrinth.getLines();i++){
                for(int j=0;j<labyrinth.getRows();j++){
                    if(!labyrinth.getSide(i,j,0)){
                        g.drawLine(50+i*10,50+j*10,
                                50+i*10+10,50+j*10);
                    }

                    if(!labyrinth.getSide(i,j,1)){
                        g.drawLine(50+i*10,50+j*10,
                                50+i*10,50+j*10+10);
                    }
                }
            }
        }
    }
}